/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Internal;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Pins;
import com.dustedpixels.cirt.model.core.Script;

/**
 * 16-bit register with separate hi & lo buses.
 * 
 * <p>
 * It's optimized for 8-bit data transfer.
 *
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class Reg16HiLo {
  @In @Pins(8) public int inHi;
  @In @Pins(8) public int inLo;
  
  @In public boolean reset;
  @In public boolean writeHi;
  @In public boolean writeLo;
  
  @Out @Pins(8) public int outHi;
  @Out @Pins(8) public int outLo;
  
  @Internal @Pins(8) public int valueHi;
  @Internal @Pins(8) public int valueLo;
  
  @Script
  public void update() {
    if (reset) {
      valueHi = 0xFF;
      valueLo = 0xFF;
    } else {
      if (writeHi) {
        valueHi = inHi;
      }
      
      if (writeLo) {
        valueLo = inLo;
      }
    }
    
    outHi = valueHi;
    outLo = valueLo;
  }
}
